<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/02/xpath-functions">
	<xsl:param name="DOTNET2"/>

	<xsl:template match="Class">
		<xsl:variable name="Name" select="Name"/>
		<xsl:variable name="HeaderInfo" select="HeaderInfo/ProjectName"/>
// GENNIT Facebook ASP.NET http://www.gennit.com
//
// Project: <xsl:value-of select="HeaderInfo/ProjectName"/>
//
// **************************************************************
// IMPORTANT BIT:
//
// This source code is is owned by you. No copyright is held by
// GENNIT. However, please note the disclaimer below
// **************************************************************
//
// GENNIT refers to the GENNIT website and anyone affiliated
// with the GENNIT system. Including but not limited to
// the administrator and service provider.
//
// Unless agreed to in writing, source code is distributed on an 
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. GENNIT are not responsible for 
// your use/misuse of this code.

// When you use GENNIT code, you do so at your own risk and 
// GENNIT is not responsible for the accuracy, 
// reliability or functionality of the code. GENNIT expressly 
// disclaims any potential liability associated with use of 
// this generated code.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


// Note this namespace may differ from your default.aspx
namespace <xsl:value-of select="HeaderInfo/ProjectName"/>
{

    <![CDATA[/// <summary>
    /// Default.aspx Facebook implementation.
    /// </summary>]]>
    public partial class _Default : System.Web.UI.Page
    {


        // FacebookService initialization
        Facebook.Components.FacebookService _fbService =
                new Facebook.Components.FacebookService ( );

        Facebook.User _fbUser;



        <![CDATA[/// <summary>
        /// Occurs on page load
        /// </summary>]]>
        protected void Page_Load ( object sender , EventArgs e )
        {
 
            // P3P Policy may be required for ASP.NET applications using cookies within facebook
            // See http://wiki.f8.facebook.com/index.php/Gotchas#Privacy_Policy

            // Uncomment the lines below if required.
            // HttpContext.Current.Response.AddHeader ( "p3p", 
            //      "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");



            // Sets up facebook parameters
            SetupFacebookService ( );

            // Gets a Facebook session
            GetFacebookSession ( );

            // Gets the Facebook userid making the call.
            GetFacebookUserId ( );



            if ( _fbUser != null )
            {
                Response.Write ( string.Format ( "Facebook UserID: {0} Firstname: {1}" , 
                    _fbUser.UserId , _fbUser.FirstName ) );

                // Setting FBML (A window on the users facebook page is possible with the lines below)
                // Note however, you will need a modified version of the Facebook.dll
                // The source code for the Facebook API is included, add the project located at
                // C:\Program Files\Coding4Fun\Facebook\Source\csharp\Facebook\facebook.csproj
                // and add lines as directed @
                // http://wiki.f8.facebook.com/index.php/ASP.NET_Microsoft_Dev_Kit#Facebook.cs_-.3E_SetFBML
                //
                // Into facebookservice.cs

                // Uncomment these lines when done
                // _fbService.SetFBML ( string.Format ( "Facebook UserID: {0} Firstname: {1}" , 
                //      _fbUser.UserId , _fbUser.FirstName ) );
            }


        }



        <![CDATA[/// <summary>
        /// Setup the Facebook service parameters
        /// </summary>]]>
        private void SetupFacebookService ( )
        {
            // Your Facebook application key as issued to you by Facebook for this application
            _fbService.ApplicationKey = "<xsl:value-of select="HeaderInfo/ref1"/>";

            // Your Facebook secret key as issued to you by Facebook for this application
            _fbService.Secret = "<xsl:value-of select="HeaderInfo/ref2"/>";


            // Assumption you are building an embedded facebook web application
            _fbService.IsDesktopApplication = false;
        }


        <![CDATA[/// <summary>
        /// Gets a Facebook Session
        /// </summary>]]>
        private void GetFacebookSession ( )
        {
            string sessionKey = Session[ "Facebook_session_key" ] as string;
            string userId = Session[ "Facebook_userId" ] as string;
            string authToken = Request.QueryString[ "auth_token" ];

            if ( !String.IsNullOrEmpty ( sessionKey ) )
            {
                _fbService.SessionKey = sessionKey;
                _fbService.UserId = userId;
            }
            else if ( !String.IsNullOrEmpty ( authToken ) )
            {
                _fbService.CreateSession ( authToken );
                Session[ "Facebook_session_key" ] = _fbService.SessionKey;
                Session[ "Facebook_userId" ] = _fbService.UserId;
                Session[ "Facebook_session_expires" ] = _fbService.SessionExpires;
            }
            else
            {
                Response.Redirect ( @"http://www.facebook.com/login.php?api_key=" +
                       _fbService.ApplicationKey + @"&amp;v=1.0" );
            }


        }


        <![CDATA[/// <summary>
        /// Gets the Facebook userid making the call
        /// </summary>]]>
        private void GetFacebookUserId ( )
        {
            try
            {
                // Try and get the userid that is making the call, if this fails
                // then get the user to login to Facebook.
                _fbUser = _fbService.GetUserInfo ();
            }
            catch ( Facebook.Exceptions.FacebookTimeoutException )
            {
                Response.Redirect ( @"http://www.facebook.com/login.php?api_key=" +
                    _fbService.ApplicationKey + @"&amp;v=1.0" );
            }
        }



    }
}

		
		
		
	</xsl:template>
	
	
	
	
	
	
</xsl:stylesheet>